<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <title>环境数据查询</title>
    <link rel="stylesheet" href="../../../../../public/dist/css/layui.css">
</head>
<body>
<blockquote class="layui-elem-quote layui-text">
    环境数据查询
</blockquote>
<form class="layui-form" action="" lay-filter="example" id="example">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">测量内容</label>
            <div class="layui-input-inline">
                <select name="a" lay-verify="" id='a' search-type="a">
                    <option value="一氧化碳">一氧化碳</option>
                    <option value="二氧化碳">二氧化碳</option>
                    <option value="PM10">PM10</option>
                    <option value="PM2.5">PM2.5</option>
                    <option value="环境温度">环境温度</option>
                    <option value="环境湿度">环境湿度</option>
                    <option value="土壤PH值">土壤PH值</option>
                    <option value="水质PH值">水质PH值</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">企业名称</label>
            <div class="layui-input-inline">
                <input type="text" name="b" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">基地</label>
            <div class="layui-input-inline">
                <input type="text" name="c" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">地块</label>
            <div class="layui-input-inline">
                <input type="text" name="d" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">传感器</label>
            <div class="layui-input-inline">
                <input type="text" name="e" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">测量时间</label>
            <div class="layui-input-inline">
                <input type="date" name="f" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">监测结果</label>
            <div class="layui-input-inline">
                <input type="text" name="g" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn cancels">取消</button>
        </div>
    </div>
</form>
</body>
<script src="../../../../../js/module/jquery-3.4.1.min.js"></script>
<script src="../../../../../public/dist/layui.js" charset="utf-8"></script>
<script src="../../../../../js/common/api.js"></script>
<script type="text/javascript">
    var dataId = null;
    layui.config({
        base: '../../../../../js/module/'
    }).use(['Tool', 'form', 'layedit', 'laydate', "serviceTools"], function () {
        var laydate = layui.laydate;

        laydate.render({
            elem: '#date' //指定元素
        });
        layui.Tool.init();
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate,
            serviceTools = layui.serviceTools;
        //监听提交
        form.on('submit(demo1)', function (data) {
            var type = localStorage.getItem("type");
            if (type === null) {
                alert("数据类型不能为空")
            } else {
                var zd = {
                    id: dataId === null ? "" : dataId,
                    type: type,
                    context: JSON.stringify(data.field),
                    // keyword:data.field.farmName+"|"+data.field.detectionOrderNo
                    keyword: data.field.a + "|" + data.field.b
                }
                serviceTools.EditOrSaveOrDelete({
                    parame: zd,
                    url: baseaip + "dictionaries/saveOrUpdate",
                    callback: (function () {
                        window.history.back(-2);
                    })()
                })

            }
            return false;
        });

        // console.info(location.href.split("?")[1])
        getHrefId();

    });

    function getHrefId() {
        var loc = location.href;
        console.log(loc);
        var url = loc.split("?")[1];
        console.log(url);
        if (url && url != '') {
            var para = url.split("&");
            var len = para.length;
            var res = {};
            var arr = [];
            for (var i = 0; i < len; i++) {
                arr = para[i].split("=");
                res[arr[0]] = arr[1];
            }
            dataId = res.id;
            var dataJson = localStorage.getItem([res.id]);
            dataJson != null && dataJson.trim().length > 0 ? (function () {
                data = JSON.parse(dataJson);
                setForm(data);
            })() : "";

        } else {

        }

    }

    function setForm(data) {
        layui.use(['form'], function () {
            console.log(data);
            console.log('data');
            layui.form.val('example', JSON.parse(data.context));
        })
    }

</script>

</html>